﻿using System;
using System.Net.Http;
using System.Threading.Tasks;

namespace LinqToOwin.Web.Labs.Data
{
  internal sealed class GoogleMapsClient
  {
    private static readonly Uri serviceUrl = new Uri("http://maps.googleapis.com/maps/api/streetview?size=200x200&heading=235&sensor=false", UriKind.Absolute);

    public static async Task<byte[]> GetMapAsync(decimal latitude, decimal longitude)
    {
      var url = serviceUrl.AbsoluteUri
              + "&location=" + latitude + ',' + longitude
              + "&key=AIzaSyDTi-NtITj-JV4BXR6E7ks6Lt3jEZfrtGU";

      using (var client = new HttpClient())
      {
        return await client.GetByteArrayAsync(url).ConfigureAwait(false);
      }
    }
  }
}